const mongoose = require('mongoose');
var express = require('express')
var industry = express()

const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const {industryService } = require('../../service/impl/industryService/index');


industry.post('/post/industry/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await industryService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  industry.post('/post/industry/delete', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      result =  await industryService.getIns().findByIdAndDelete(id)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  industry.post('/post/industry/update', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      let updates = req.body.updates
      result =  await industryService.getIns().findByIdAndUpdate(id,updates)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  industry.post('/post/industry/query', async (req,res) => {
    let result
    try {
      result =  await industryService.getIns().find()
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  module.exports= industry


